﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HallControl
{
    public partial class HallControl : UserControl
    {
        private bool isOccupied = false;
        public Color defaultColor = Color.Gray;
        public Color highlightColor = Color.Blue;

        public event EventHandler<MovementClickEventArgs> MovementClick;

        public HallControl()
        {
            InitializeComponent();
        }

        public bool IsOccupied
        {
            get
            {
                return isOccupied;
            }
            set
            {
            }
        }

        public void AddPlayer(Color c)
        {
            if (!isOccupied)
            {
                pictureBox1.BackColor = c;
            }
        }

        public void RemovePlayer()
        {
            pictureBox1.BackColor = Color.Tan;
        }

        public void RemovePlayer(Color c)
        {
            if (pictureBox1.BackColor == c)
            {
                pictureBox1.BackColor = Color.Tan;
            }
            else
            {
                throw new Exception("Player " + c + " was not found in " + this.Name);
            }
        }

        public void SetHighlight()
        {
            this.BackColor = highlightColor;
        }

        public void RemoveHighlight()
        {
            this.BackColor = defaultColor;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            SendMovementClickMessage(null);
        }

        private void HallControl_Load(object sender, EventArgs e)
        {
            SendMovementClickMessage(null);
        }

        /// <summary>
        /// Start Trun
        /// </summary>
        /// <param name="s"></param>
        private void SendMovementClickMessage(String s)
        {
            MovementClickEventArgs args = new MovementClickEventArgs();
            args.room = s;
            OnMovementClickMessage(args);
        }
        protected virtual void OnMovementClickMessage(MovementClickEventArgs e)
        {
            EventHandler<MovementClickEventArgs> handler = MovementClick;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }

    public class MovementClickEventArgs : EventArgs
    {
        public String room { get; set; }
    }
}
